package b3.widget.home.user
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	import b3.scene.home.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.geom.*;
	
	import com.greensock.*;

	public class DarkPane extends BasicWidget
	{
		private var darkBar:MaskProgressBar;
		private var darkText:TextField;
		private var levelText:TextField;
		private var titleText:TextField;
		
		public function DarkPane()
		{
			super();
			var DarkBar:Class = ResourceHelper.getInstance().getClassByName("DarkBar");
			darkBar = new MaskProgressBar(DarkBar);
			addChild(darkBar);
			darkText = new TextField();
			darkText.selectable = false;
        	darkText.autoSize = TextFieldAutoSize.CENTER;
			darkText.defaultTextFormat = new TextFormat(BFont.fontName, 10, 0x000000);
			darkText.x = 37;
			darkText.y = -6;
			addChild(darkText);
			levelText = new TextField();
			levelText.selectable = false;
        	levelText.autoSize = TextFieldAutoSize.CENTER;
			levelText.defaultTextFormat = new TextFormat(BFont.fontName, 11, 0x880000);
			levelText.x = 2;
			levelText.y = 10;
			addChild(levelText);
			titleText = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
			titleText.defaultTextFormat = new TextFormat(BFont.fontName, 11, 0x880000);
			titleText.x = 38;
			titleText.y = 10;
			addChild(titleText);
			PlayerManager.getInstance().me.packageModel.addEventListener(ModelEvent.REFRESH, onRefresh);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			this.mouseChildren = false;
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.showOperationTip("DarkIcon", "黑暗，通过攻击好友获得", 0x880000);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.clear();
		}

		private function onRefresh(event:Event):void
		{
			var me:Player = PlayerManager.getInstance().me;
			var dark:int = me.packageModel.getObjectNum(ObjConfig.DARK);
			var level:int = Config.getLevel(ObjConfig.DARK, dark);
			var currentHonourConfig:HonourConfig = Config.honourArrays[ObjConfig.DARK][level];
			var nextHonourConfig:HonourConfig = Config.honourArrays[ObjConfig.DARK][level + 1];
			darkBar.percentage = dark / nextHonourConfig.require;
			darkText.text = dark + "/" + nextHonourConfig.require;
			levelText.htmlText = "<i>" + level + ". </i>";
			titleText.text = currentHonourConfig.title;
		}

		//播放黑暗值增加动画
		public function playAddMovie(startPos:Point, num:int):void
		{
			var targetPos:Point = this.localToGlobal(new Point(50, 0));
			HomeScene.getInstance().playCoinIncreaseMovie("DarkIcon", num, 0x880000, startPos, targetPos);
			TweenLite.delayedCall(2, onRefresh, [null]);
		}
	}
}